<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="br.usp.ime.amazon.ResultSearch"%>
<%@page import="br.usp.ime.amazon.Book"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Amazon.com Search</title>
<link type="text/css" href="style.css" rel="styleSheet" />
</head>
<body>
<%
		out.println("<p> <a href=\"Search\"> Try another search - Amazon.com </a></p>");
		out.println("<p> <a href=\"SearchGoogleBooks\"> Try another search - GoogleBooks.com </a></p>");
		if (session.getAttribute("result") == null){
			out.println("<p> <b>There are not results that match your search criteria.</b></p>");
		}else{
			
			ResultSearch r = (ResultSearch) session.getAttribute("result");
			out.println("<p><b>" + r.getTotal()+ "</b> results for query <b>\""+session.getAttribute("query")+"\"</b>.</p>");
			
			out.println("<table id=\"box-table-a\" summary=\"Results for search\">");
		    out.println("<thead>");
		    out.println("<tr>");
		    out.println("<th> Item </th>");
		    out.println("<th> Image </th>");
		    out.println("<th> Title </th>");
		    out.println("<th> Authors </th>");
		    out.println("<th> Manufacture </th>");
		    out.println("<th> Edition </th>");
		    out.println("<th> PublicationDate</th>");
		    out.println("<th> ISBN </th>");
		    out.println("<th> Link </th>");          
		    out.println("</tr>");
		    out.println("</thead>");
			out.println("<tbody>");
			
			int i = 1;
			for (Book l : r.getBooks()) {
				out.println("<tr>");
				out.println("<td>" + i++ + "</td>");
				out.println("<td>");
				if(l.getUrlLargeImage()!=null){
					out.println("<a href=\""+l.getUrlLargeImage()+"\" target=\"_blank\">");
					out.println("<img src=\""+ l.getUrlMediumImage()+ "\" width=\"40\" height=\"60\" alt=\"No Image\" title=\"Click to view large image\"/></a>");
				}
				out.println("</td>");
				out.println("<td>" + l.getTitle() + "</td>");
				out.print("<td>");
				
				
				for (String str : l.getAutores())
					out.println(str + "<br/>");
				
				out.print("</td>");
				out.println("<td>" + l.getManufacture()+ "</td>");
				out.println("<td>"+ l.getEdition()+ "</td>");
				out.println("<td>"+ l.getPublication() + "</td>");
				out.println("<td>"+ l.getIsbn() + "</td>");
				out.println("<td> <a href=\"" + l.getDetailPageURL()	+ "\" target=\"_blank\" title=\"Click to visit Amazon.com\">[+]</a></td>");
				out.println("</tr>");
			}
			out.println("</tbody>");
			out.println("</table>");
		}
	%>
</body>
</html>